package com.tj.jinzao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tj.jinzao.R;
import com.tj.jinzao.base.BaseListAdapter;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.FriendBean;
import com.tj.jinzao.model.ZXSBean;
import com.tj.jinzao.widgets.RoundedImageView;

import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by LiuYX on 2019/4/19.
 */

public class ZXSAdapter extends BaseListAdapter<FriendBean, ZXSAdapter.ViewHolder> {
    private int type,pos;
    private ArrayList<ZXSBean> list=new ArrayList<>();
    public ZXSAdapter(Context context, CopyOnWriteArrayList<FriendBean> data,int type) {
        super(context, data);
        this.type=type;
    }
    public ArrayList<ZXSBean> getList(){
        return list;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_friend_zxs, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        FriendBean friendBean = mData.get(position);
        if(friendBean!=null){
            if(friendBean.getNickname()!=null){
                holder.name.setText(friendBean.getNickname());
            }else {
                holder.name.setText("");
            }
            Glide.with(mContext).load(Constant.IMAGE_PREFIX + friendBean.getImgurl()).into(holder.avatar);
        }else {
            holder.name.setText("");
            holder.avatar.setImageResource(R.mipmap.default_head_man);
        }
        if(mData.size()>0&&mData.get(position).isSelect()==true){
            holder.check.setChecked(true);
        }else {
            holder.check.setChecked(false);
        }
        holder.check.setVisibility(View.VISIBLE);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name, vip, follow, date, content;
        RoundedImageView avatar;
        CheckBox check;
        LinearLayout content_lay;

        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.nickName);
            avatar = itemView.findViewById(R.id.avatar);
            content_lay = itemView.findViewById(R.id.content_lay);
            check = itemView.findViewById(R.id.check);
        }
    }

}
